package com.example.tosf.web;

import cn.hutool.core.date.DateUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.http.HttpUtil;

import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author：lzf
 * @Date: 2022/6/29
 */
public class HongyuCron {

    public static void methods() throws SQLException {
        System.out.println("这里是HongyuCron定时任务11111!"+DateUtil.now());
        Db.use().execute("TRUNCATE TABLE ads_hy");
        List<String> typelinkedList=new LinkedList<>();
        typelinkedList.add("ssc");
        typelinkedList.add("wpc");
        typelinkedList.add("gsc");
        typelinkedList.add("shisc");

        List<String> orgCodeList=new LinkedList<>();
        orgCodeList.add("ddq");
        orgCodeList.add("hnq");
        orgCodeList.add("sjtq");
        orgCodeList.add("yhq");
        orgCodeList.add("sbxq");
        orgCodeList.add("hgq");
        orgCodeList.add("shq");
        orgCodeList.add("hpq");
        orgCodeList.add("txq");
        orgCodeList.add("jkq");

        orgCodeList.add("qs");

        for(int i=0;i<typelinkedList.size();i++){
            for(int j=0;j<orgCodeList.size();j++){
                String url="https://www.swkjzhhw.com/ICP/app/getUseValueByCarType.do?type=";
                String type=typelinkedList.get(i);
                String orgCode=orgCodeList.get(j);
                if(!orgCode.equals("qs")){
                    url+=typelinkedList.get(i)+"&orgCode="+orgCodeList.get(j);
                }else{
                    url+=typelinkedList.get(i);
                }


                String value= HttpUtil.get(url);

                Db.use().insert(
                        Entity.create("ads_hy")
                                .set("type", type)
                                .set("org_code", orgCode)
                                .set("value",value)
                );
            }
        }
        System.out.println("这里是HongyuCron定时任务22222!"+DateUtil.now());
    }
}
